#ifndef SETUP_H
#define SETUP_H
#include <Arduino.h>
/////////////////////// 设备版本号/////////////////////////////
// #define SmartKB32_v1
#define SmartKB32_v2
//////////////////////////////////////////////////////////////

#define PIN 13
#define BUZZ 0
#ifdef SmartKB32_v1
#define RTS 5 // MCU通知模块MCU是否准备好
#define CTS 4 // 模块通知MCU模块是否准备好
#define M74HC165_CE
#endif
#define M74HC165_PL 15
#define M74HC165_CLK 14
#define M74HC165_MISO 12

#define M74HC595_SCK 5
#define M74HC595_CLK 2
#define M74HC595_MOSI 4

#define DS1302_RST 16
#define DS1302_SCK 14
#define DS1302_DATA 12

#define serial_print_success "FULL" // 键盘数据发送成功效验码
#define gettime_kb "GTTM"
typedef enum
{
      KEY_X2Y1,
      KEY_X2Y2,
      KEY_X2Y3,
      KEY_X2Y4,
      KEY_X3Y1,
      KEY_X3Y2,
      KEY_X3Y3,
      KEY_X3Y4,
      KEY_X4Y1,
      KEY_X4Y2,
      KEY_X4Y3,
      KEY_X4Y4,
      KEY_X5Y2,
      KEY_X5Y3,
      KEY_X5Y4,
      KEY_X6Y3,
      KEY_X6Y4,

      KEY_X1Y2,
      KEY_X1Y3,
      KEY_X1Y4,

      KEY_X1Y5,
      KEY_X2Y5,

      KEY_X3Y5,
      KEY_X4Y5,
      KEY_X5Y5,
      KEY_X6Y5,

      KEY_X7Y2,
      KEY_X7Y3,
      KEY_X7Y4,
      KEY_X7Y5,

      KEY_X1Y1,
      KEY_X7Y1
};

typedef enum
{
      KEY_DOWN_X2Y1 = 1,
      KEY_DOWN_X2Y2,
      KEY_DOWN_X2Y3,
      KEY_DOWN_X2Y4,
      KEY_DOWN_X3Y1,
      KEY_DOWN_X3Y2,
      KEY_DOWN_X3Y3,
      KEY_DOWN_X3Y4,
      KEY_DOWN_X4Y1,
      KEY_DOWN_X4Y2,
      KEY_DOWN_X4Y3,
      KEY_DOWN_X4Y4,
      KEY_DOWN_X5Y2,
      KEY_DOWN_X5Y3,
      KEY_DOWN_X5Y4,
      KEY_DOWN_X6Y3,
      KEY_DOWN_X6Y4,

      KEY_DOWN_X1Y2, // 快捷软件启动
      KEY_DOWN_X1Y3,
      KEY_DOWN_X1Y4,

      KEY_DOWN_X1Y5, // 音量调节开始
      KEY_DOWN_X2Y5,

      KEY_DOWN_X3Y5, // 台灯控制开始
      KEY_DOWN_X4Y5,
      KEY_DOWN_X5Y5,
      KEY_DOWN_X6Y5,

      KEY_DOWN_X7Y2, // 桌面电源控制
      KEY_DOWN_X7Y3,
      KEY_DOWN_X7Y4,
      KEY_DOWN_X7Y5,

      // 单击抬起
      KEY_UP_X2Y1,
      KEY_UP_X2Y2,
      KEY_UP_X2Y3,
      KEY_UP_X2Y4,
      KEY_UP_X3Y1,
      KEY_UP_X3Y2,
      KEY_UP_X3Y3,
      KEY_UP_X3Y4,
      KEY_UP_X4Y1,
      KEY_UP_X4Y2,
      KEY_UP_X4Y3,
      KEY_UP_X4Y4,
      KEY_UP_X5Y2,
      KEY_UP_X5Y3,
      KEY_UP_X5Y4,
      KEY_UP_X6Y3,
      KEY_UP_X6Y4,

      KEY_UP_X1Y2, // 快捷软件启动
      KEY_UP_X1Y3,
      KEY_UP_X1Y4,

      KEY_UP_X1Y5, // 音量调节结束
      KEY_UP_X2Y5,

      KEY_UP_X3Y5, // 台灯控制结束
      KEY_UP_X4Y5,
      KEY_UP_X5Y5,
      KEY_UP_X6Y5,

      KEY_UP_X7Y2, // 桌面电源控制
      KEY_UP_X7Y3,
      KEY_UP_X7Y4,
      KEY_UP_X7Y5,

      KEY_DOWN_X1Y1, // 按下提示
      KEY_DOWN_X7Y1, // 按下提示
      KEY_UP_X1Y1,   // 映射表切换
      KEY_UP_X7Y1,   // dial/lvgl切换

      // 双按键按下
      DOUB_KEY_DOWN_X2Y1,
      DOUB_KEY_DOWN_X2Y2,
      DOUB_KEY_DOWN_X2Y3,
      DOUB_KEY_DOWN_X2Y4,
      DOUB_KEY_DOWN_X3Y1,
      DOUB_KEY_DOWN_X3Y2,
      DOUB_KEY_DOWN_X3Y3,
      DOUB_KEY_DOWN_X3Y4,
      DOUB_KEY_DOWN_X4Y1,
      DOUB_KEY_DOWN_X4Y2,
      DOUB_KEY_DOWN_X4Y3,
      DOUB_KEY_DOWN_X4Y4,
      DOUB_KEY_DOWN_X5Y2,
      DOUB_KEY_DOWN_X5Y3,
      DOUB_KEY_DOWN_X5Y4,
      DOUB_KEY_DOWN_X6Y3,
      DOUB_KEY_DOWN_X6Y4,

      DOUB_KEY_DOWN_X1Y2,
      DOUB_KEY_DOWN_X1Y3,
      DOUB_KEY_DOWN_X1Y4,

      DOUB_KEY_DOWN_X1Y5,
      DOUB_KEY_DOWN_X2Y5,

      DOUB_KEY_DOWN_X3Y5,
      DOUB_KEY_DOWN_X4Y5,
      DOUB_KEY_DOWN_X5Y5,
      DOUB_KEY_DOWN_X6Y5,

      DOUB_KEY_DOWN_X7Y2,
      DOUB_KEY_DOWN_X7Y3,
      DOUB_KEY_DOWN_X7Y4,
      DOUB_KEY_DOWN_X7Y5,

      // 双按键抬起
      DOUB_KEY_UP_X2Y1,
      DOUB_KEY_UP_X2Y2,
      DOUB_KEY_UP_X2Y3,
      DOUB_KEY_UP_X2Y4,
      DOUB_KEY_UP_X3Y1,
      DOUB_KEY_UP_X3Y2,
      DOUB_KEY_UP_X3Y3,
      DOUB_KEY_UP_X3Y4,
      DOUB_KEY_UP_X4Y1,
      DOUB_KEY_UP_X4Y2,
      DOUB_KEY_UP_X4Y3,
      DOUB_KEY_UP_X4Y4,
      DOUB_KEY_UP_X5Y2,
      DOUB_KEY_UP_X5Y3,
      DOUB_KEY_UP_X5Y4,
      DOUB_KEY_UP_X6Y3,
      DOUB_KEY_UP_X6Y4,

      DOUB_KEY_UP_X1Y2, // 映射表指定切回至默认映射表
      DOUB_KEY_UP_X1Y3, // 映射表指定切回至数字映射表
      DOUB_KEY_UP_X1Y4, // 映射表指定切回至APP映射表

      DOUB_KEY_UP_X1Y5, // 一键休眠
      DOUB_KEY_UP_X2Y5,

      DOUB_KEY_UP_X3Y5,
      DOUB_KEY_UP_X4Y5,
      DOUB_KEY_UP_X5Y5,
      DOUB_KEY_UP_X6Y5,

      DOUB_KEY_UP_X7Y2,
      DOUB_KEY_UP_X7Y3,
      DOUB_KEY_UP_X7Y4,
      DOUB_KEY_UP_X7Y5
};

extern bool main_cpu_sleep;
#define rgb_mode_num 3
extern uint8_t rgb_mode;
void keyboard_init();
void keyboard_run();

void rgb_init();
void rgb_run();
void music_rgb();

extern uint8_t LEEDDD;

typedef struct
{
      uint8_t year;
      uint8_t month;
      uint8_t day;
      uint8_t hour;
      uint8_t minute;
      uint8_t second;
      uint8_t dow;
} DateTime;

/**
 * Months of year
 */
enum MONTH : uint8_t
{
      MONTH_JAN = 1,
      MONTH_FEB = 2,
      MONTH_MAR = 3,
      MONTH_APR = 4,
      MONTH_MAY = 5,
      MONTH_JUN = 6,
      MONTH_JUL = 7,
      MONTH_AUG = 8,
      MONTH_SET = 9,
      MONTH_OCT = 10,
      MONTH_NOV = 11,
      MONTH_DEC = 12
};

/**
 * Days of week
 */
enum DOW : uint8_t
{
      DOW_MON = 1,
      DOW_TUE = 2,
      DOW_WED = 3,
      DOW_THU = 4,
      DOW_FRI = 5,
      DOW_SAT = 6,
      DOW_SUN = 7
};
void Ds1302_init();
void getDateTime(DateTime *dt);
void setDateTime(DateTime *dt);
void state_led_init();
void state_led_sendData(uint8_t data);
#endif
